import { defineStore } from "pinia";

export const useTokenStore = defineStore(
  "token",
  () => {
    // token
    const token = ref("");
    function setToken(str: string) {
      token.value = str;
    }

    // 清除用户信息
    function clearToken() {
      token.value = "";
    }

    return {
      token,
      setToken,
      clearToken,
    };
  },
  {
    persist: {
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
        getItem(key) {
          return uni.getStorageSync(key);
        },
      },
    },
  }
);
